import RPi.GPIO as GPIO
import time,os

num = 0

GPIO.setmode(GPIO.BCM)
GPIO.setup(25,GPIO.IN,pull_up_down = GPIO.PUD_UP)
#GPIO.add_event_detect(537,GPIO.FALLING,bouncetime = 500)
while True:
  if GPIO.input(25) == 0:
    print('...External power off...')
    os.system('sync')
    print('...Data saving...')
    time.sleep(3)
    os.system('sync')
    print('...Power off in five seconds...')
    print('')
    while num <5:
      s = 5-num
      print('.....'+str(s)+'....')
      num = num+1
      time.sleep(1)
#      os.system('sudo shutdown -h now')
